﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>示例demo</title>
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <link href="~/layuimini/css/public.css" rel="stylesheet" />
    <style>
        .layui-input{
            height:25px;
            
        }
        .layui-form-item .layui-input-inline {
            float: left;
            width: 140px;
            margin-right: 10px;
        }
        .layui-form-pane .layui-form-label {
            width: 80px;
            padding: 2px 5px;
            height: 25px;
            line-height: 20px;
            border-width: 1px;
            border-style: solid;
            border-radius: 2px 0 0 2px;
            text-align: center;
            background-color: #FBFBFB;
            overflow: hidden;
            box-sizing: border-box;
        }
    </style>
</head>
    
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <fieldset class="table-search-fieldset" style="margin-bottom:5px;">
                <legend>一车间后道流程卡</legend>
                <div style="margin: 5px 10px 5px 10px" class="layui-form-pane">
                    <form class="layui-form" action="" lay-filter="example">
                        <input type="hidden" name="ID" value="" id="IndexID"/>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">流程卡号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="Code" lay-verify="required" autocomplete="off" class="layui-input" disabled="disabled">
                                </div>
                            </div>
                           <div class="layui-inline" style="display:none;">
                                <label class="layui-form-label">产品编号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="GoodsCode" lay-verify="required" autocomplete="off" class="layui-input" id="GoodsCode" disabled="disabled">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">产品型号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="GoodsModel" lay-verify="required" autocomplete="off" class="layui-input" id="GoodsModel" disabled="disabled">
                                </div>
                            </div>
                            <div class="layui-inline" style="display:none;">
                                <label class="layui-form-label">晶圆编号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="SourceGoodsCode" lay-verify="required" autocomplete="off" class="layui-input" id="SourceGoodsCode" disabled="disabled">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">晶圆型号</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="SourceGoodsModel" lay-verify="required" autocomplete="off" class="layui-input" id="SourceGoodsModel" disabled="disabled">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">晶圆尺寸</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="SourceGoodsSize" lay-verify="required" autocomplete="off" class="layui-input" disabled="disabled">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">芯片尺寸</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="GoodsSize" autocomplete="off" class="layui-input" disabled="disabled">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">投片数量</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="TouQty" lay-verify="required|number" autocomplete="off" class="layui-input" disabled="disabled">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">设计数量</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="SheQty" autocomplete="off" class="layui-input" disabled="disabled">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">正背面金属</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="ZhengBei" autocomplete="off" class="layui-input" disabled="disabled">
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    {{#  if( @(Web.Common.Common.IsAuthoritys(14)) == 1 && @(ViewBag.model.State) < 2){ }}
                    <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add" onclick="add()">添加工序</button>
                    @*<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>*@
                    {{#  } }}
                </div>
            </script>
            <table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
            @*<table class="layui-hide" id="table" lay-filter="currentTableFilter"></table>*@
            <script type="text/html" id="currentTableBar">
                {{#  if( @(Web.Common.Common.IsAuthoritys(14)) == 1 && @(ViewBag.model.State) < 2){ }}
                {{#  if(d.PID==0){ }}
                <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="add">添加</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delpro">删除</a>
                {{#  } }}
                {{#  if(d.PID!='0'){ }}
                <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
                @*<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="addstuff">材料</a>*@
                {{#  } }}
                {{#  } }}
                {{#  if(d.PID!='0'){ }}
                {{#  if( @(Web.Common.Common.IsAuthoritys(32)) == 1 && d.CheckUserID==0 && @(ViewBag.model.State) < 2){ }}
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="check">检验</a>
                {{#  } }}
                {{#  } }}
            </script>
        </div>
    </div>
    <script src="~/layui/layui.js"></script>
    <script>
        var editObj=null,ptable=null,treeGrid=null,tableId='treeTable',layer=null;
        layui.config({
            base: '/layui/extend/'
        }).extend({
            treeGrid:'treeGrid'
        }).use(['jquery','treeGrid','layer'], function(){
            var $=layui.jquery;
            treeGrid = layui.treeGrid;//很重要
            layer = layui.layer;
            form = layui.form;

            form.val('example', {
                "ID": "@ViewBag.model.ID"
                , "GoodsID": "@ViewBag.model.GoodsID"
                , "GoodsCode": "@ViewBag.model.GoodsCode"
                , "GoodsName": "@ViewBag.model.GoodsName"
                , "GoodsModel": "@ViewBag.model.GoodsModel"
                , "GoodsSize": "@ViewBag.model.GoodsSize"
                , "SourceGoodsID": "@ViewBag.model.SourceGoodsID"
                , "SourceGoodsCode": "@ViewBag.model.SourceGoodsCode"
                , "SourceGoodsName": "@ViewBag.model.SourceGoodsName"
                , "SourceGoodsModel": "@ViewBag.model.SourceGoodsModel"
                , "SourceGoodsSize": "@ViewBag.model.SourceGoodsSize"
                , "Code": "@ViewBag.model.Code"
                , "TouQty": "@ViewBag.model.TouQty"
                , "SheQty": "@ViewBag.model.SheQty"
                , "ZhengBei": "@ViewBag.model.ZhengBei"
            })





            ptable=treeGrid.render({
                id:tableId
                ,elem: '#'+tableId
                , url: '/Bill2/DetailsListAsync'
                , where: {
                    IndexID: $('#IndexID').val(),
                }
                ,cellMinWidth: 100
                ,idField:'MID'//必須字段
                ,treeId:'MID'//树形id字段名称
                ,treeUpId:'PID'//树形父id字段名称
                ,treeShowName:'ProName'//以树形式显示的字段
                ,heightRemove:[".dHead",190]//不计算的高度,表格设定的是固定高度，此项不生效
                ,height: 'full-190'
                ,isFilter:false
                ,iconOpen:true//是否显示图标【默认显示】
                ,isOpenDefault:false//节点默认是展开还是折叠【默认展开】
                ,loading:true
                ,method:'post'
                , isPage: false
                , toolbar: '#toolbarDemo'
                ,defaultToolbar: [{ layEvent: 'refresh', icon: 'layui-icon-refresh',title:'刷新' }, 'filter', 'exports', 'print']
                //,size:'sm'
                ,cols: [[
                    //{type:'numbers'}
                    //,{type:'radio'}
                    //,{type:'checkbox',sort:true}
                         { field: 'ProName', title: '工　序', width: 200 , fixed: 'left'}
                        , { field: 'ShowIndex', title: '工序号' }
                        , { field: 'InQty', title: '接收数' }
                        , { field: 'OutQty', title: '下传数' }
                        , { field: 'FanQty', title: '返工数' }
                        , { field: 'FailQty', title: '废品数' }
                        , { field: 'FailRemark', title: '废品原因' }
                        , { field: 'TaskTime', title: '工时(分钟)' }
                        , { field: 'BiaoZhunQty', title: '工时标准' }
                        //, { field: 'GongYi', title: '工艺条件' }
                        , { field: 'Operator', title: '操作者' }
                        , { field: 'BeginDate', title: '开始日期' }
                        , { field: 'EndDate', title: '结束日期' }
                        , { field: 'CheckMan', title: '检验员' }
                        , { field: 'CheckDate', title: '检验日期' }
                        , { field: 'CheckRemark', title: '检验结果' }
                        //, { field: 'WenDu', title: '温度' }
                        //, { field: 'ShiDu', title: '湿度' }
                        , { field: 'Remark', title: '备注' }
                    , {
                        width: 100, title: '操作', toolbar: '#currentTableBar', fixed: 'right', width: 200
                    }
                ]]
                ,parseData:function (res) {//数据加载后回调
                    return res;
                }
                ,onClickRow:function (index, o) {
                    console.log(index,o,"单击！");
                    //openorclose(o.MID);
                    //msg("单击！,按F12，在控制台查看详细参数！");
                }
                ,onDblClickRow:function (index, o) {
                    console.log(index,o,"双击");
                    //msg("双击！,按F12，在控制台查看详细参数！");
                }
                ,onCheck:function (obj,checked,isAll) {//复选事件
                    console.log(obj,checked,isAll,"复选");
                    //msg("复选,按F12，在控制台查看详细参数！");
                }
                ,onRadio:function (obj) {//单选事件
                    console.log(obj,"单选");
                    // msg("单选,按F12，在控制台查看详细参数！");
                }
            });

            treeGrid.on('tool(' + tableId + ')', function (obj) {
                var data = obj.data;
                if(obj.event === 'del'){//删除行
                    del(obj);
                } else if (obj.event === "add") {//添加行
                    if (data.State!=1) {
                        layer.msg('投产状态才能添加操作记录。', { icon: 5 },
                                function () {

                                });
                        return;
                    }
                    var index = layer.open({
                        title: '工序详情',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: false,
                        area: ['1100px', '550px'],
                        content: '@Url.Action("BillDetailsEdit", "Bill2")?BillProcedureID='+data.ID,
                        end: function () {
                            query();

                        }
                    });
                } else if (obj.event === "edit") {//添加行
                    var index = layer.open({
                        title: '工序详情',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: false,
                        area: ['1100px', '550px'],
                        content: '@Url.Action("BillDetailsEdit", "Bill2")?BillProcedureID='+data.ProID+'&ID='+data.ID,
                        end: function () {
                            query();

                        }
                    });
                } else if (obj.event === "addstuff") {//添加行
                    var index = layer.open({
                        title: '材料详情',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: false,
                        area: ['1100px', '700px'],
                        content: '@Url.Action("BillDetailsStuffList", "Bill2")?BillDetailsID='+data.ID,
                        end: function () {
                            query();

                        }
                    });
                } else if (obj.event === "delpro") {//添加行
                    layer.confirm('删除工序会一并删除下面所有操作记录及材料记录，确认吗？', {
                        btn: ['是的', '取消'] //按钮
                    }, function () {
                        $.ajax({
                            url: '@Url.Action("BillProceduresDelAsync", "Bill2")',
                            type: "post",
                            dataType: "json",
                            data: { IDs: data.ID },
                            success: function (obj) {
                                //Info,Success,Warning,Error
                                var type = obj.Type;
                                if (type == 1) {
                                    layer.msg(obj.Content,
                                        {
                                            icon: 6, time: 2000
                                        },
                                        function () {
                                            query();
                                        });
                                } else {
                                    layer.msg(obj.Content, { icon: 5, time: 2000 });
                                }
                            }
                        });
                    }, function () {
                        return;
                    });
                } else if (obj.event === "delete") {//添加行
                    layer.confirm('删除操作记录会一并删除材料记录，确认吗？', {
                        btn: ['是的', '取消'] //按钮
                    }, function () {
                        $.ajax({
                            url: '@Url.Action("BillDetailsDelAsync", "Bill2")',
                            type: "post",
                            dataType: "json",
                            data: { IDs: data.ID },
                            success: function (obj) {
                                //Info,Success,Warning,Error
                                var type = obj.Type;
                                if (type == 1) {
                                    layer.msg(obj.Content,
                                        {
                                            icon: 6, time: 2000
                                        },
                                        function () {
                                            query();
                                        });
                                } else {
                                    layer.msg(obj.Content, { icon: 5, time: 2000 });
                                }
                            }
                        });
                    }, function () {
                        return;
                    });
                } else if (obj.event === "check") {//检验
                    layer.prompt({title: '输入检验结果', formType: 0}, function(remark, index){
                        $.ajax({
                            url: '@Url.Action("BillDetailsCheckEditAsync", "BasicInfo")',
                            type: "post",
                            dataType: "json",
                            data: { BillNameID:2,ID:data.ID,Remark:remark},
                            success: function (data) {
                                //Info,Success,Warning,Error
                                var type = data.Type;
                                if (type == 1) {
                                    layer.msg(data.Content,
                                        {
                                            icon: 6, time: 2000
                                        },
                                        function () {
                                            layer.close(index);
                                            query();
                                        });
                                } else {
                                    layer.msg(data.Content, { icon: 5, time: 2000 });
                                }
                            }
                        });
                    });
                }
            });;


            treeGrid.on('toolbar(treeTable)', function (obj) {
                if (obj.event === 'add') {  // 监听添加操作
                    var index = layer.open({
                        title: '添加工序',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: false,
                        area: ['1200px', '400px'],
                        content: '@Url.Action("BillProceduresEdit", "Bill2")?IndexID='+$('#IndexID').val(),
                        end: function () {
                            RefreshTable();

                        }
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                }
            });

        });

        function del(obj) {
            layer.confirm("你确定删除数据吗？如果存在下级节点则一并删除，此操作不能撤销！", {icon: 3, title:'提示'},
                function(index){//确定回调
                    obj.del();
                    layer.close(index);
                },function (index) {//取消回调
                    layer.close(index);
                }
            );
        }


        var i=1000000;
        //添加
        function add() {
            var index = layer.open({
                title: '添加工序',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: false,
                area: ['1100px', '400px'],
                content: '@Url.Action("BillProceduresEdit", "Bill2")?IndexID=@ViewBag.model.ID',
                end: function () {
                    query();

                }
            });
        }

        function print() {
            console.log(treeGrid.cache[tableId]);
            msg("对象已打印，按F12，在控制台查看！");
        }

        function msg(msg) {
            var loadIndex=layer.msg(msg, {
                time:3000
                ,offset: 'b'//顶部
                ,shade: 0
            });
        }

        function openorclose(mid) {
            var map=treeGrid.getDataMap(tableId);
            var o= map[mid];
            treeGrid.treeNodeOpen(tableId,o,!o[treeGrid.config.cols.isOpen]);
        }


        function openAll() {
            var treedata=treeGrid.getDataTreeList(tableId);
            treeGrid.treeOpenAll(tableId,!treedata[0][treeGrid.config.cols.isOpen]);
        }

        function getCheckData() {
            var checkStatus = treeGrid.checkStatus(tableId)
                ,data = checkStatus.data;
            layer.alert(JSON.stringify(data));
        }
        function radioStatus() {
            var data = treeGrid.radioStatus(tableId)
            layer.alert(JSON.stringify(data));
        }
        function getCheckLength() {
            var checkStatus = treeGrid.checkStatus(tableId)
                ,data = checkStatus.data;
            layer.msg('选中了：'+ data.length + ' 个');
        }

        function reload() {
            treeGrid.reload(tableId,{
                page:{
                    curr:1
                }
            });
        }
        function query() {
            treeGrid.query(tableId,{
                where:{
                    IndexID: @ViewBag.model.ID,
                }
            });
        }

        function test() {
            console.log(treeGrid.cache[tableId],treeGrid.getClass(tableId));


            /*var map=treeGrid.getDataMap(tableId);
            var o= map['102'];
            o.name="更新";
            treeGrid.updateRow(tableId,o);*/
        }
    </script>

</body>
</html>